package com.swsc.xapp.xroom;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.RawQuery;
import androidx.sqlite.db.SupportSQLiteQuery;

import java.util.List;

@Dao
public interface DefectDao extends BaseDao<DefectDO> {

    @Query("SELECT * FROM SOLAR_DEFECT WHERE id IN (:id)")
    DefectDO getById(Integer id);

    @Query("SELECT * FROM SOLAR_DEFECT WHERE defect_no IN (:defectNo)")
    DefectDO getByDefectNo(Long defectNo);

    @Query("SELECT COUNT(id) FROM SOLAR_DEFECT WHERE organ_no = :organNo")
    int countByOrganNo(Integer organNo);

    @Query("SELECT * FROM SOLAR_DEFECT WHERE tenant_no = :tenantNo AND organ_no =:organNo AND defect_no = :defectNo")
    DefectDO getByDefect(Integer tenantNo, Integer organNo, Long defectNo);

    @Query("DELETE FROM SOLAR_DEFECT WHERE tenant_no = :tenantNo AND organ_no =:organNo")
    void deleteByTenantOrgan(Integer tenantNo, Integer organNo);

    @Override
    default String getTableName() {
        return "solar_defect";
    }
}
